package is.BlackWhiteSquares.formulas;

import is.BlackWhiteSquares.formulas.Casilla.ColorCasilla;

import java.awt.Color;
import java.util.ArrayList;
import java.util.List;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;

import es.deusto.ingenieria.is.search.formulation.State;
import es.deusto.ingenieria.is.search.xml.StateXMLReader;

public class EnvironmentXMLReader extends StateXMLReader {

	private int posCasilla;
	private List <Casilla> listaCas;
	

	public EnvironmentXMLReader(String xmlFile) {
		super(xmlFile);
	}
	
	public State getState() {
		return new BlWhSquaresEnvironment(this.listaCas,this.posCasilla);
	}

	public void startElement(String uri, String localName, String qName,Attributes attributes) throws SAXException {

		try {		
			if (qName.equals("is:lineofsquares")) {
				listaCas =new ArrayList<Casilla>();
				this.posCasilla=0;
			} else if (qName.equals("is:white")) {
				
				listaCas.add(new Casilla(ColorCasilla.WHITE));

			} else if (qName.equals("is:black")	)			
					{	
				listaCas.add(new Casilla(ColorCasilla.BLACK));
			}
		} catch (Exception ex) {
			System.out.println(this.getClass().getName() + ".startElement(): " + ex);
		}
	}
	
}